package com.youbug.system.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.youbug.system.entity.Card;
import com.youbug.system.entity.Carousel;
import com.youbug.kefu.entity.Chat;
import com.youbug.kefu.service.*;
import com.youbug.system.vo.CardVo;
import com.youbug.common.vo.R;
import com.youbug.system.service.ICardService;
import com.youbug.system.service.ICarouselService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 通用查询前端控制器
 * </p>
 *
 * @author youbug
 * @since 2023-02-12
 */
@RestController
@RequestMapping("/portal")
public class PortalController {

    @Autowired
    private ICarouselService carouselService;
    @Autowired
    private ICardService cardService;

    @Autowired
    private IChatService chatService;

    @PostMapping("/getCarousels")
    public R<List<Carousel>> getAnsmts(@RequestBody Carousel carousel){

        List<Carousel> carousels = carouselService.listBy(carousel);

        return R.ok(carousels);
    }

    @PostMapping("/getCards")
    public R<List<Card>> getCards(@RequestBody CardVo card){

        List<Card> cards = cardService.listBy(card);

        return R.ok(cards);
    }

    @GetMapping("/satisfy/{chatId}/{score}")
    public R<Boolean> satisfy(@PathVariable Long chatId, @PathVariable Integer score){

        QueryWrapper<Chat> wrapper = new QueryWrapper<>();
        wrapper.eq("id", chatId);

        Chat chat = new Chat();
        chat.setSatisfaction(score);

        boolean update = chatService.update(chat, wrapper);

        return R.ok(update);
    }


}

